package com.huan.ai.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 控制器
 *
 * @author huan.fu
 * @date 2025/6/8 - 08:49
 */
@RestController
public class ChatController {

    @Resource
    private ChatClient chatClient;

    /**
     * 阻塞调用
     *
     * @param prompt 用户提示词
     * @return ai响应
     */
    @GetMapping("blockChat")
    public String blockChat(String prompt) {
        return chatClient.prompt()
                .user(prompt)
                .call()
                .content();
    }

    /**
     * 阻塞调用
     *
     * @param prompt 用户提示词
     * @return ai响应
     */
    @GetMapping(value = "streamChat", produces = "text/html;charset=utf-8")
    public Flux<String> streamChat(String prompt) {
        return chatClient.prompt()
                .user(prompt)
                .stream()
                .content();
    }
}
